#定义好友字典
friends = {
    1: {'name': '小明', 'phone': '001', 'address': '广州'},
    2: {'name': '小红', 'phone': '002', 'address': '深圳'},
    3: {'name': '小王', 'phone': '003', 'address': '北京'}
}

#添加好友
def add_friend(friends, id, name, phone, address):
        if id in friends:
            print("联系人已存在")
        else:
            friends[id] = {'姓名': name, '电话': phone, '地址': address}
            print(f"添加成功！")


# 删除联系人
def delete_friend(friends, id):
    if id in friends:
        del friends[id]
        print("删除成功！.")
    else:
        print("无此联系人")

#修改联系人信息
def update_friend(friends, id, name=None, phone=None, address=None):
    if id in friends:
        if name is not None:
            friends[id]['name'] = name
        if phone is not None:
            friends[id]['phone'] = phone
        if address is not None:
            friends[id]['address'] = address
        print("修改成功！")
    else:
        print("无此联系人！")

#查找联系人
def get_friend(friends, id):
    if id in friends:
        friend_info = friends[id]
        print(f"姓名: {friend_info['name']}, 电话: {friend_info['phone']}, 地址: {friend_info['address']}")
    else:
        print("无此联系人！")

# 测试
# 添加好友
add_friend(friends, 4, '小李', '004', '上海')

# 查询好友
get_friend(friends, 1)

# 更新好友信息
update_friend(friends, 1, name='小华', phone='101', address='武汉新洲区')

# 再次查询，确认更新
get_friend(friends, 1)

# 删除好友
delete_friend(friends, 2)

# 尝试查询已删除的好友
get_friend(friends, 2)








